package com.zilu.digitaltwin.dto.req;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.zilu.digitaltwin.entity.NumberAttribute;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: NumberAttributeReqDTO
 * @Description:
 * @Author: 段振宇
 * @Date: 2023/1/5 11:00
 */
@NoArgsConstructor
@Data

public class NumberAttributeReqDTO {

    @JsonProperty("categoryCode")
    @NotBlank(message = "categoryCode不能为空")
    private String categoryCode;
    @JsonProperty("numberType")
    @NotBlank(message = "numberType不能为空")
    private String numberType;
    @NotBlank(message = "实体类型不能为空")
    @JsonProperty("entityType")
    private String entityType;
    @JsonProperty("item")
    @NotEmpty(message = "item不能为空")
    private List<ItemDTO> item;

    @NoArgsConstructor
    @Data
    public static class ItemDTO {
        @JsonProperty("startIndex")
        private Integer startIndex;
        @JsonProperty("endIndex")
        private Integer endIndex;
        @JsonProperty("color")
        private String color;

    }

    public List<NumberAttribute> convertToNumberAttribute(Integer dicId){
        return item.stream().map(i -> {
            NumberAttribute attribute = new NumberAttribute();
            attribute.setColor(i.getColor());
            attribute.setDicId(dicId);
            attribute.setStartIndex(i.getStartIndex());
            attribute.setEndIndex(i.getEndIndex());
            return attribute;
        }).collect(Collectors.toList());
    }



}
